/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.sys.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.sys.dao.SecurityLogDao;
import com.thinkgem.jeesite.modules.sys.entity.SecurityLog;

/**
 * 授权日志Service
 * @author fanqinglong
 * @version 2018-06-06
 */
@Service
@Transactional(readOnly = true)
public class SecurityLogService extends CrudService<SecurityLogDao, SecurityLog> {

	public SecurityLog get(String id) {
		return super.get(id);
	}
	
	public List<SecurityLog> findList(SecurityLog securityLog) {
		return super.findList(securityLog);
	}
	
	public Page<SecurityLog> findPage(Page<SecurityLog> page, SecurityLog securityLog) {
		securityLog.getSqlMap().put("dateSQL", getDateSQL(securityLog));
		return super.findPage(page, securityLog);
	}
	
	@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = false, rollbackFor = Exception.class)
	public void save(SecurityLog securityLog) {
		super.save(securityLog);
	}
	
	@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = false, rollbackFor = Exception.class)
	public void delete(SecurityLog securityLog) {
		super.delete(securityLog);
	}
	
	private String getDateSQL(SecurityLog securityLog){
		StringBuffer stringBuffer = new StringBuffer();
		if (!StringUtils.isEmpty(securityLog.getDateFrom())) {
			stringBuffer.append(" AND a.create_date >= '"+securityLog.getDateFrom()+"' ");
		}
		if (!StringUtils.isEmpty(securityLog.getDateTo())) {
			stringBuffer.append(" AND a.create_date <= '"+securityLog.getDateTo()+"' ");
		}
		return stringBuffer.toString();
	}
}